/**
 * 
 */
package util;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
 * @author rnaidu
 *
 */
public class SeleniumWait extends basetest.BaseTest {
	
	
	// wait
	public void waitforPagetoLoad(int time) {

		driver.manage().timeouts().pageLoadTimeout(time, TimeUnit.SECONDS);

	}

	public void wait(int time) {

		driver.manage().timeouts().implicitlyWait(time, TimeUnit.SECONDS);

	}

	public void pause(double secondsToWait) {

		try {
			Thread.sleep((int) (secondsToWait * 1000));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	// wait for element to be clickable

	public void waitforElementtobeClickableByxpath(int time,String objectName) {

		WebDriverWait wait = new WebDriverWait(driver, time);
		WebElement element = wait.until(ExpectedConditions
				.elementToBeClickable(By.xpath(OR.getProperty(objectName))));
	}

	public void waitforElementtobeClickablebyClass(int time, String objectName) {

		WebDriverWait wait = new WebDriverWait(driver, time);
		WebElement element = wait
				.until(ExpectedConditions.elementToBeClickable(By.className(OR
						.getProperty(objectName))));
	}

	public void waitforElementtobeClickablebyCss(int time,String objectName) {

		WebDriverWait wait = new WebDriverWait(driver, time);
		WebElement element = wait
				.until(ExpectedConditions.elementToBeClickable(By
						.cssSelector(OR.getProperty(objectName))));
	}

	public void waitforElementtobeClickablebyID(int time, String objectName) {

		WebDriverWait wait = new WebDriverWait(driver, time);
		WebElement element = wait.until(ExpectedConditions
				.elementToBeClickable(By.id(OR.getProperty(objectName))));
	}

	

}
